(function () {
    const jifen = document.querySelector('.jifen').children[0];
    const gery = document.querySelector('.fc-gery');
    const pointer = document.querySelector('.pointer');
    let uid = sessionStorage.getItem('uid');
    // 用户获取积分
    if (uid) {
        axios.get('/api/setScore', {
            params: { uid }
        }).then(res => {
            // console.log(res)
            if (res.data.status === 1) {
                jifen.innerHTML = res.data.score;
            }
        }).catch(err => {
            console.error(err);
        })
    }
    // 签到
    pointer.addEventListener('click', scoreFn);
    function scoreFn() {
        $(function () {
            $('#pointer').addClass('animated bounceIn');
        });
        $(function () {
            $('#gery').addClass('animated bounceInDown');
        });
        // 点击后自增加1积分
        const score = ++jifen.innerHTML;
        axios.post('/api/updateScore', { score }
        ).then(function (res) {
            console.log(res);
            if (res.data.code === 1) {
                pointer.innerHTML = res.data.msg;
                gery.innerHTML = '今日已签到，明日签到+1分';
                pointer.removeEventListener('click', scoreFn);
            }
        }).catch(function (err) {
            console.log(err);
        });
    }
}
)();